home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Debuggers & dcmds / MacsBug 6.5.2 / dcmds / C Samples / Drvr.c next >
Encoding:
C/C++ Source or Header  |  1995-07-26  |  6.0 KB  |  269 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Drvr.c
  3.  
  4.     Contains:    This is the Unit Table dcmd.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.                 DAL = Dave Lyons
  8.                 sad = Scott Douglass
  9.  
  10.     Copyright:    © 1988,1993-1994 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <4>   10-Dec-94    JM3        Updated for new format 3 dcmd requirements.
  15.          <3>     3/14/94    DAL        Re-layed-out the columns: removed Window and made room for
  16.                                     everything to be nice on 13" monitors. Made the "that's strange"
  17.                                     message not show up for dRef = 0xFFFE (.Sony for HD-20). Now
  18.                                     Hoon is happy.
  19.          <2>     9/14/93    DAL        made the driver name column wider
  20.  
  21.     Modification history:
  22.          7Dec88 sad        show driver version
  23.         29Nov88 sad        revised for new dcmd names
  24.         13Oct88 sad        written from file.c
  25.  
  26.     The following MPW commands will build the dcmd and copy it to the
  27.     "Debugger Prefs" file in the System folder. The dcmd's name in
  28.     MacsBug will be the name of the file built by the Linker.
  29.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  30.     C Samples folder into this folder.
  31.  
  32.     C Put.c
  33.     C Drvr.c
  34.     Link dcmdGlue.a.o Drvr.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o Drvr
  35.     BuildDcmd Drvr 1000
  36.     Echo 'include "Drvr";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  37. */
  38.  
  39. #ifdef USESTDIO
  40.     #include <stdio.h>
  41. #endif
  42.  
  43. #include <Types.h>
  44. #include <Memory.h>
  45. #include <Devices.h>
  46. #include <SysEqu.h>
  47.  
  48. #include "dcmd.h"
  49. #include "put.h"
  50.  
  51.  
  52. typedef struct DRVR
  53. {
  54.     short drvrFlags;
  55.     short drvrDelay;
  56.     short drvrEMask;
  57.     short drvrMenu;
  58.     short drvrOpen;
  59.     short drvrPrime;
  60.     short drvrCtl;
  61.     short drvrStatus;
  62.     short drvrClose;
  63.     Str255 drvrName;
  64. } DRVR;
  65.  
  66.  
  67. static void DrawHdr()
  68. {
  69. //                    0         1         2         3         4         5         6         7         8         9
  70. //                    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
  71.     dcmdDrawLine("\pdRef dNum Driver                      Flg  Ver   qHead   Storage Dely  Drvr at DCE at");
  72. }
  73.  
  74. #define kColumnNameEnd         37
  75. #define kColumnVersionEnd    46
  76. #define kColumnQHeadEnd        54
  77. #define kColumnStorageEnd    64
  78. #define kColumnDriverAtEnd    78
  79. #define kColumnDCEAtEnd        85
  80.  
  81.  
  82. static void DrawDCE(int dref, AuxDCE* dcep)
  83. {
  84.     DRVR*    drvrp;
  85.  
  86.     PutUHexWord(dref);
  87.     PutSpace();
  88.     PutUHexWord(~dref);
  89.     PutSpace();
  90.     if (dcep->dCtlFlags & 0x40)
  91.     {
  92.         if (dcep->dCtlDriver)
  93.         {
  94.             drvrp = * (DRVR **) dcep->dCtlDriver;
  95.             if (drvrp)
  96.                 PutPStrTruncTo(drvrp->drvrName, kColumnNameEnd);
  97.             else
  98.                 PutPStrTruncTo("\p-purged-", kColumnNameEnd);
  99.         }
  100.         else
  101.         {
  102.             PutPStrTruncTo("\p",kColumnNameEnd);
  103.         };
  104.     }
  105.     else
  106.     {
  107.         if (dcep->dCtlDriver)
  108.         {
  109.             drvrp = (DRVR*)dcep->dCtlDriver;
  110.             PutPStrTruncTo(drvrp->drvrName,kColumnNameEnd);
  111.         }
  112.         else
  113.         {
  114.             PutPStrTruncTo("\p",kColumnNameEnd);
  115.         };
  116.     };
  117.     PutSpace();
  118.     PutChar((dcep->dCtlFlags & 0x80) ? 'B' : 'b');
  119.     PutChar((dcep->dCtlFlags & 0x40) ? 'H' : 'P');
  120.     PutChar((dcep->dCtlFlags & 0x20) ? 'O' : 'C');
  121.     PutSpace();
  122.     PutUDecTo((unsigned char) dcep->dCtlQHdr.qFlags,kColumnVersionEnd);            // version
  123.     PutSpace();
  124.     PutUHexZTo((unsigned long) dcep->dCtlQHdr.qHead,8,kColumnQHeadEnd);            // qHead
  125.     PutSpace();
  126.     PutUHexZTo((unsigned long) dcep->dCtlStorage,8,kColumnStorageEnd);            // Storage
  127.     PutSpace();
  128.     PutUHexWord((unsigned long) dcep->dCtlDelay);
  129.     PutSpace();
  130.     PutUHexZTo((unsigned long) drvrp,8,kColumnDriverAtEnd);
  131.     PutSpace();
  132.     PutUHexZTo((unsigned long) dcep,8,kColumnDCEAtEnd);
  133.     PutLine();
  134.  
  135.     // For drvr FFFE (.Sony for the HD20, pre-SCSI), it's okay that
  136.     // the dCtlRefNum is $FFFB (don't whine about it)
  137.  
  138.     if ( (dref != dcep->dCtlRefNum) && ( ((unsigned short) dref) != (unsigned short) 0xFFFE) )
  139.     {
  140.         PutPStr("\p   that is strange:  dCtlRefNum = ");
  141.         PutUHexWord(dcep->dCtlRefNum);
  142.         PutLine();
  143.     }
  144. } // DrawDCE
  145.  
  146.  
  147. pascal void CommandEntry(dcmdBlock* paramPtr)
  148. {
  149.  
  150.     static const Str255 usageStr = "\p[refNum|num]";
  151.  
  152.     switch (paramPtr->request)
  153.     {
  154.         case dcmdInit:
  155.             break;
  156.  
  157.         case dcmdHelp:
  158.             dcmdDrawLine("\pDisplays driver information for the given refNum or all installed");
  159.             dcmdDrawLine("\pdrivers. Flags are B/b=Busy, H/P=Handle/Ptr, O/C=Open/Closed.");
  160.             break;
  161.  
  162.         case dcmdGetInfo:
  163.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
  164.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  165.             break;
  166.  
  167.         case dcmdDoIt:
  168.         {
  169.             Boolean doOne = false;
  170.             long dref;
  171.             int NumDCEs;
  172.  
  173.             dcmdSwapWorlds();
  174.  
  175.             dcmdDrawLine("\pDisplaying Driver Control Entries");
  176.  
  177.             // Get low-memory values after dcmdSwapWorlds().
  178.  
  179.             NumDCEs = *(unsigned short *)UnitNtryCnt;
  180.  
  181.             (void)dcmdGetNextExpression(&dref, &doOne);
  182.  
  183.             if (doOne)
  184.             {
  185.                 int dnum;
  186.                 dref = (short)dref;
  187.                 if (dref < 0)
  188.                     dnum = ~dref;
  189.                 else
  190.                 {
  191.                     dnum = dref;
  192.                     dref = ~dref;
  193.                 }
  194.                 if (dnum > NumDCEs)
  195.                 {
  196. #ifdef USESTDIO
  197.                     Str255 line;
  198.                     sprintf(line,"Bad refnum 0x%.4x",(unsigned short)dref);
  199.                     dcmdDrawLine((Str255)c2pstr(&line));
  200. #else
  201.                     PutPStr("\pBad refnum ");
  202.                     PutUHexWord(dref);
  203.                     PutSpace();
  204.                     PutUHexWord(~dref);
  205.                     PutLine();
  206. #endif
  207.                 }
  208.                 else
  209.                 {
  210.                     AuxDCE** dceh = (*(AuxDCE****)UTableBase)[dnum];
  211.                     if (dceh)
  212.                     {
  213.                         DrawHdr();
  214.                         DrawDCE(dref,*dceh);
  215.                     }
  216.                     else
  217.                     {
  218.                         PutPStr("\pDriver ");
  219.                         PutUHexWord(dref);
  220.                         PutSpace();
  221.                         PutUHexWord(~dref);
  222.                         PutPStr("\p is not in installed");
  223.                         PutLine();
  224.                     }
  225.                 }
  226.             }
  227.             else
  228.             {
  229.                 int DCEsUsed = 0;
  230.                 int dnum;
  231.                 AuxDCE*** dcehp;
  232.                 Boolean foundOne = false;
  233.                 for(dnum = 0, dcehp = *(AuxDCE****)UTableBase; dnum < NumDCEs; dnum++, dcehp++)
  234.                 {
  235.                     if (*dcehp)
  236.                     {
  237.                         DCEsUsed++;
  238.                         if (!foundOne)
  239.                         {
  240.                             DrawHdr();
  241.                             foundOne = true;
  242.                         }
  243.                         DrawDCE(~dnum,**dcehp);
  244.                     }
  245.                     if (paramPtr->aborted) break;
  246.                 }
  247.                 if(!paramPtr->aborted)
  248.                 {
  249.                     PutUDec(NumDCEs);
  250.                     PutPStr("\p Unit Table entries, ");
  251.                     PutUDec(DCEsUsed);
  252.                     PutPStr("\p in use, ");
  253.                     PutUDec(NumDCEs - DCEsUsed);
  254.                     PutPStr("\p free");
  255.                     PutLine();
  256.                 }
  257.             }    
  258.  
  259.             dcmdSwapWorlds();
  260.             break;
  261.         }
  262.  
  263.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  264.  
  265.         default:
  266.             break;
  267.     }
  268. }
  269.